using System.Drawing;

namespace NGridDrawer.Partitions
{
    /// <LastUpdate author="Blaise Braye" Date="15/06/2008 17:01"/>
    /// <summary>
    /// Represents an individual element in a <see cref="PartitionGrid"/>.
    /// </summary>
    /// <remarks>
    /// an element in a <see cref="PartitionGrid"/> is defined 
    /// with a tuple of a <see cref="PartitionLevel"/> and a <see cref="PartitionColumn"/>
    /// </remarks>
    public class PartitionElement : PartitionGridElement
    {
        private readonly int _columnId;
        private readonly int _levelId;
        private readonly int _ordinal;
        private SizeF _size;


        /// <param name="grid">The <see cref="PartitionGrid"/> object associated with this element</param>
        /// <param name="levelId">The <see cref="PartitionLevel"/> index of this element</param>
        /// <param name="columnId">The <see cref="PartitionColumn"/> index of this element</param>
        public PartitionElement(PartitionGrid grid, int levelId, int columnId)
            : base(grid)
        {
            _ordinal = grid.GetPartitionOrdinal(levelId, columnId);
            _levelId = levelId;
            _columnId = columnId;
        }

        /// <summary>
        /// Gets The Ordinal value of this element
        /// </summary>
        public int Ordinal
        {
            get { return _ordinal; }
        }

        /// <summary>
        /// Gets the <see cref="PartitionColumn"/> index of this element
        /// </summary>
        public int ColumnId
        {
            get { return _columnId; }
        }

        /// <summary>
        /// Gets the <see cref="PartitionLevel"/> index of this element
        /// </summary>
        public int LevelId
        {
            get { return _levelId; }
        }

        /// <summary>
        /// Gets the <see cref="PartitionColumn"/> object which contains this element
        /// </summary>
        public PartitionColumn Column
        {
            get { return Grid.PartitionColumn(ColumnId); }
        }

        /// <summary>
        /// Gets the <see cref="PartitionLevel"/> object which contains this element
        /// </summary>
        public PartitionLevel Level
        {
            get { return Grid.PartitionLevel(LevelId); }
        }

        /// <summary>
        /// Gets the Size of the element
        /// </summary>
        /// <remarks>
        /// This information is recovered
        /// from the <see cref="Column"/> width and the <see cref="Level"/> height.
        /// </remarks>
        public SizeF Size
        {
            get
            {
                if (_size.Equals(SizeF.Empty))
                {
                    _size = new SizeF(Column.Width, Level.Height);
                }
                return _size;
            }
        }
    }
}